package com.leyou.item.web;

import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/5/4 0004
 * Time: 16:41
 */
@RestController
@RequestMapping("spec")
public class SpecParamController {
    @Autowired
    private SpecParamService specParamService;

    @GetMapping("params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParam(@RequestParam(value = "gid", required = false) Long gid,
                                                             @RequestParam(value = "cid", required = false) Long cid,
                                                             @RequestParam(value = "searching", required = false) Boolean searching){
        return ResponseEntity.ok(specParamService.querySpecParam(gid, cid,searching));
    }

    @PutMapping("param")
    public ResponseEntity<Void> editSpecParam(@RequestBody SpecParamDTO specParamDTO) {
        specParamService.editSpecParam(specParamDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @PostMapping("param")
    public ResponseEntity<Void> addSpecParam(@RequestBody SpecParamDTO specParamDTO) {
        specParamService.addSpecParam(specParamDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @DeleteMapping("param/{id}")
    public ResponseEntity<Void> deleteSpecParamById(@PathVariable("id") Long id) {
        specParamService.deleteSpecParamById(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

}
